//
//  XLLevelUpSheetView.m
//  XiangLove
//
//  Created by 李传坤 on 2018/3/27.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLLevelUpSheetView.h"

@interface XLLevelUpSheetView ()

@property (strong, nonatomic) UIImageView *LevelImageView;
@property (strong, nonatomic) UILabel *CongratulationLabel;//恭喜label

@property (strong, nonatomic) UIView *alertView;
@property (strong, nonatomic) UIButton *dismissButton;



@end

@implementation XLLevelUpSheetView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 设置背影为透明色
        self.backgroundColor = [UIColor clearColor];
        [self addViews];
    }
    return self;
}
- (void)addViews{
    _dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _dismissButton.backgroundColor = [UIColor blackColor];_dismissButton.alpha = 0.3;
    _dismissButton.frame = self.bounds;
    [_dismissButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_dismissButton];
    
    _alertView = [[UIView alloc]init];
    _alertView.backgroundColor = kWhiteColor;
    _alertView.layer.cornerRadius = 10;
    _alertView.center = CGPointMake(self.width/2,self.height/2);
    _alertView.frame = CGRectMake(SCREEN_WIDTH/2 - 140, SCREEN_HEIGHT/2 - 140, 280, 260);
    [self addSubview:_alertView];
    
    _LevelImageView = [[UIImageView alloc]init];
    _LevelImageView.frame = CGRectMake(0, 0, _alertView.frame.size.width,180);
    _LevelImageView.image = [UIImage imageNamed:@"me_grade_icons_huizhang2"];
    [_alertView addSubview:_LevelImageView];
    
    _LevelLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, _LevelImageView.frame.size.height - 70, 280, 20)];
    _LevelLabel.text = @"LV.0";
    _LevelLabel.textColor = kWhiteColor;
    _LevelLabel.textAlignment = NSTextAlignmentCenter;
    [_alertView addSubview:_LevelLabel];
    
    _CongratulationLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, _alertView.frame.size.height - 90, 280, 20)];
    _CongratulationLabel.text = @"恭喜你升级了";
    _CongratulationLabel.textColor = RGB_HEX(0xFFbb01);
    _CongratulationLabel.textAlignment = NSTextAlignmentCenter;
    _CongratulationLabel.font = [UIFont systemFontOfSize:20];
    [_alertView addSubview:_CongratulationLabel];
    
    _bottomAlertLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, _alertView.frame.size.height - 50, 280, 20)];
    _bottomAlertLabel.text = @"最新得到的等级lv.0";
    _bottomAlertLabel.textColor = RGB_HEX(0xffbb01);
    _bottomAlertLabel.textAlignment = NSTextAlignmentCenter;
    _bottomAlertLabel.font = [UIFont systemFontOfSize:16];
    [_alertView addSubview:_bottomAlertLabel];
    
}
#pragma mark -   设置字体颜色
-(void)chageColorLabel:(UILabel *)labell AndRange:(NSRange )range
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labell.text];
    //设置文字颜色
    [str addAttribute:NSForegroundColorAttributeName value:RGB_HEX(0x767676) range:range];
    
    labell.attributedText = str;
}
-(void)show{
    [[[[UIApplication sharedApplication]delegate]window]addSubview:self];
    [self chageColorLabel:_bottomAlertLabel AndRange:NSMakeRange(0, 7)];

}
-(void)dismiss{
    [UIView animateWithDuration:0.3
                          delay:0.0
                        options: UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.alpha = 0;
                     }
                     completion:^(BOOL finished){
                         [self removeFromSuperview];
                     }];
}


@end
